package com.lemon.smartsafety.ui.activity.safe.data;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.BundleKey;
import com.lemon.smartsafety.entity.safe.company.CompanyBuildingIndexVo;
import com.lemon.smartsafety.entity.safe.company.CompanyBuildingItemCountVo;
import com.lemon.smartsafety.entity.safe.company.CompanyBuildingVo;
import com.lemon.smartsafetynew.ui.activity.base.BaseSearchFragmentActivity;
import com.lemon.smartsafety.ui.fragment.safe.data.BuildingBaseCheckItemListFragment;
import com.lemon.smartsafety.utils.common.LoggerHelper;
import com.lemon.smartsafety.utils.common.StringUtils;

/**
 * Created by Cooliean on 16/1/24.
 * 安全巡查 检查项目 基础数据 供选择使用的
 */
public class BuildingBaseCheckItemListActivity extends BaseSearchFragmentActivity {
    private LoggerHelper loggerHelper = new LoggerHelper(BuildingBaseCheckItemListActivity.class);

    private BuildingBaseCheckItemListFragment mFragment;

    private String mOldValue = null;
    /**
     * bundle info
     */
    private CompanyBuildingVo          mCompanyBuildingVo;
    private CompanyBuildingIndexVo     mCompanyBuildingIndexVo;
    private CompanyBuildingItemCountVo mCompanyBuildingItemCountVo;

    @Override
    protected void getBundleArgs() {
        super.getBundleArgs();
        if (getIntent().getExtras() != null) {
            mOldValue = getIntent().getStringExtra(BundleKey.OLD_SELECT_VALUE);
            mCompanyBuildingVo = (CompanyBuildingVo) getIntent().getSerializableExtra(BundleKey.COMPANY_BUILD_INFO);
            mCompanyBuildingIndexVo = (CompanyBuildingIndexVo) getIntent().getSerializableExtra(BundleKey.COMPANY_BUILDING_INDEX_VO);
            mCompanyBuildingItemCountVo = (CompanyBuildingItemCountVo) getIntent().getSerializableExtra(BundleKey.COMPANY_BUILDING_ITEM_COUNT);
        }
    }

    @Override
    protected void initViews() {
        super.initViews();
    }

    @Override
    public Fragment getFragment() {
        return getFragment(null);
    }


    public Fragment getFragment(String text) {
        Bundle bundle = new Bundle();
        if (null != mOldValue) {
            bundle.putString(BundleKey.OLD_SELECT_VALUE, mOldValue);
        }
        if (null != text) {
            bundle.putString(BundleKey.KEY_WORD, text);
        }
        bundle.putSerializable(BundleKey.COMPANY_BUILD_INFO, mCompanyBuildingVo);
        bundle.putSerializable(BundleKey.COMPANY_BUILDING_ITEM_COUNT, mCompanyBuildingItemCountVo);
        bundle.putSerializable(BundleKey.COMPANY_BUILDING_INDEX_VO, mCompanyBuildingIndexVo);
        mFragment = BuildingBaseCheckItemListFragment.newInstance();
        mFragment.setArguments(bundle);
        return mFragment;
    }

    @Override
    public int getSearchHintRes() {
        return R.string.search_common_hit;
    }


    @Override
    public boolean onQueryTextSubmit(String queryText) {
        queryText = StringUtils.nullValue(queryText);
        replaceFragment(R.id.main_content, getFragment(queryText));
        return super.onQueryTextSubmit(queryText);
    }

    @Override
    protected void initTitle() {
        this.setBarTitle(R.string.build_prop_type_list);
    }

}
